package Servlet.Test;
/*
@ClassName:     Http
@Author:        YangXu
@Need:          
@Date:          2022/4/26
@Time:          2022-04-26 9:33
*/

//


import com.sun.net.httpserver.HttpServer;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/post")
public class Http extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("接收到了post请求");
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("utf-8");
        resp.addHeader("test","123");
        resp.getWriter().write("您发起了post请求");
        Cookie cookie = new Cookie("张三","123456");
        resp.addCookie(cookie);
        resp.addDateHeader("66",222);

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("接收到了get请求");
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=utf-8");
        resp.setCharacterEncoding("utf-8");
        Cookie cookie = new Cookie("lisi","666");
        resp.addCookie(cookie);
        resp.getWriter().write("触发了get请求的操作");
    }
}
/*

 */